﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lm.Common.ExtensionMethods;

namespace Lm.Common.Auth.Client
{
    public partial class ChangePasswordForm : Form
    {
        public ChangePasswordForm()
        {
            InitializeComponent();
        }

        private void ChangePasswordForm_Load(object sender, EventArgs e)
        {
            this.MaximumSize = this.Size;
            this.MinimumSize = this.Size;
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            if (Root.ClientRoot.LoginInfo.IsLogin == false)
            {
                MessageBox.Show("请先登录");
                this.Close();               
                Root.ClientRoot.LoginForm.ShowDialog();
                return;
            }
            if (this.txtOldPassword.Text.IsNullOrBlank())
            {
                MessageBox.Show("必须输入旧密码");
                return;
            }
            if (this.txtNewPassword.Text.IsNullOrBlank())
            {
                MessageBox.Show("必须输入新密码");
                return;
            }
            if (this.txtConfirmPassword.Text.IsNullOrBlank())
            {
                MessageBox.Show("必须输入确认密码");
                return;
            }
            if (this.txtNewPassword.Text.Trim() != this.txtConfirmPassword.Text.Trim())
            {
                MessageBox.Show("两次输入的密码不一致");
                return;
            }
            try
            {
                Root.ClientRoot.NetClient.Request(new Lm.Common.Auth.Common.RequestResponseModel.ChangePassword.Request()
                {
                    Token = Root.ClientRoot.LoginInfo.GetToken(),
                    OldPassword = this.txtOldPassword.Text.Trim(),
                    NewPassword1 = this.txtNewPassword.Text.Trim(),
                    NewPassword2 = this.txtConfirmPassword.Text.Trim()
                });                
                MessageBox.Show("修改成功");
                this.txtNewPassword.Clear();
                this.txtConfirmPassword.Clear();
                this.txtOldPassword.Clear();
                this.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
